package org.com.yz.dubbo.service.impl;

import cn.hutool.core.date.DateTime;
import com.alibaba.dubbo.config.annotation.Service;
import org.com.yz.dal.dao.mapper.DepositTransactionMapper;
import org.com.yz.dal.dao.mapper.MchsubQueryMapper;
import org.com.yz.dal.dao.model.DepositTransaction;
import org.com.yz.dal.dao.model.MchsubBankCard;
import org.com.yz.dal.dao.model.MchsubQuery;
import org.com.yz.dal.dao.model.MchsubQueryEs;
import org.com.yz.dubbo.api.service.IMchsubQueryService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.UUID;

/**
 * 子商户查询接口实现类
 *
 * @ClassName MchsubQueryService
 * @Author wzc
 * @Date 2018/7/23 10:56
 **/
@Service(version = "1.0.0")
public class MchsubQueryServiceImpl implements IMchsubQueryService {


    @Autowired
    private DepositTransactionMapper depositTransactionMapper;

    @Autowired
    private MchsubQueryMapper mchsubQueryMapper;


    public MchsubQueryEs mchsubQueryHandle(MchsubQueryEs mchsubQueryEs, String sign) {
        MchsubQueryEs res = new MchsubQueryEs();
        //插入事务表
        DepositTransaction depositTransaction = new DepositTransaction();
        depositTransaction.setMchNo(mchsubQueryEs.getMchNo());
        depositTransaction.setTransactionNo(UUID.randomUUID().toString().replace("-", "").toLowerCase());//事务号
        depositTransaction.setOutTransNo(mchsubQueryEs.getOutTransNo());//外部追踪号
        depositTransaction.setIdMchAccntChargeUp(0);
        depositTransaction.setCreateTime(new DateTime());//创建时间
        depositTransaction.setTransactionType(mchsubQueryEs.getBizType());//事务类型
        depositTransaction.setUpdateTime(new DateTime());//更新时间
        depositTransactionMapper.insert(depositTransaction);
        //子商户号
        String man = mchsubQueryEs.getBizContent().getMchAccntNo();
        //查询子商户信息
        MchsubQuery mchsubQuery = mchsubQueryMapper.selectMchAccntNo(man);
        //查询子商户银行卡信息
        List<MchsubBankCard> mchsubBankCardList = mchsubQueryMapper.selectMchBandCard(man);
        if (mchsubBankCardList.size() > 0) {
            mchsubQuery.setBankCards(mchsubBankCardList);
        }
        res.setBizContent(mchsubQuery);
        return res;
    }
}
